package com.aliyun.flashsale.portal.config;

import java.util.Collections;

import com.aliyun.commons.service.SendMessageService;
import com.aliyun.commons.service.impl.SendMessageServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 消息配置
 *
 * 
 * @date 2024/12/01
 */
@Configuration
public class MessageConfig {

    /**
     * 发送消息服务
     *
     * @param username
     * @param password 密码
     * @param endpoint 端点
     * @return {@link SendMessageService }
     */
    @Bean
    public SendMessageService sendMessageService(@Value("${rocketmq.username}") String username,
        @Value("${rocketmq.password}") String password, @Value("${rocketmq.endpoint}") String endpoint,
        @Value("${rocketmq.order-fail-after-pre-deducted-inventory-topic}") String topic) {
        return new SendMessageServiceImpl(username, password, endpoint, Collections.singletonList(topic), null);
    }
}